package org.blogspot.t0yv0.marcalog.util

import javax.servlet._
import javax.servlet.http._

sealed class HttpContext(val request  : HttpServletRequest,
                         val response : HttpServletResponse) {
  def notFound =
    response.sendError(404, "The requested page was not found.");
  
  def serverError[T](msg: String) : T = {
    response.sendError(505, msg);
    throw new ServletException(msg);
  }

  def parameters : Map[String, String] = {
    val mb = Map.newBuilder[String,String];
    val ns = request.getParameterNames;
    while (ns.hasMoreElements) {
      val n = ns.nextElement.asInstanceOf[String];
      mb += ((n, request.getParameter(n)));
    }
    mb.result
  } 
}
